home *** CD-ROM | disk | FTP | other *** search
-
-
-
- UUUUSSSSPPPPSSSSEEEEMMMMAAAA((((3333PPPP)))) UUUUSSSSPPPPSSSSEEEEMMMMAAAA((((3333PPPP))))
-
-
-
- NNNNAAAAMMMMEEEE
- uspsema - acquire a semaphore
-
- CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<uuuulllloooocccckkkkssss....hhhh>>>>
-
- iiiinnnntttt uuuussssppppsssseeeemmmmaaaa ((((uuuusssseeeemmmmaaaa____tttt ****sssseeeemmmmaaaa))));;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- _u_s_p_s_e_m_a decrements the count of the previously allocated semaphore
- specified by _s_e_m_a. If the count is then negative, the semaphore will
- logically block the calling process until the count is incremented due to
- a _u_s_v_s_e_m_a(3P) call made by another process. The count can be interpreted
- in the following way: if it is greater than zero, there are 'count'
- resources available, namely 'count' processes can call _u_s_p_s_e_m_a and not
- block; if the count is negative then the absolute value of count is the
- number of waiting processes. _u_s_t_e_s_t_s_e_m_a(3P) can be used to obtain the
- semaphore count. _u_s_p_s_e_m_a can operate on either polling (those allocated
- via _u_s_n_e_w_p_o_l_l_s_e_m_a(3P)) or non-polling (those allocated via _u_s_n_e_w_s_e_m_a(3P))
- semaphores. The semantics of _u_s_p_s_e_m_a are different for the two types of
- semaphores.
-
- For non-polling semaphores, the caller is actually suspended if the
- semaphore is not available. During suspension signals may be received
- and processed. The caller must not _l_o_n_g_j_m_p out of a signal handler and
- bypass the semaphore operation as this will result in corruption of the
- internal data structures of the semaphore. It the user does this, the
- semaphore must be re-initialized via _u_s_i_n_i_t_s_e_m_a(3P). _u_s_p_s_e_m_a uses the
- _u_s_e_m_a(7M) device to perform the actual suspending of the caller if
- necessary. Processes are unblocked in FIFO order. If the current owner
- of the semaphore abnormally exits while still holding one or more
- semaphores, no corrective action is taken. This means that the only way
- a process that is blocked waiting for a semaphore to recover is to take a
- signal, longjmp out of the handler and re-initialize the semaphore (see
- _F_U_T_U_R_E _D_I_R_E_C_T_I_O_N_S).
-
- With either type of semaphore, the semaphore can be made recursive by
- using the CCCCSSSS____RRRREEEECCCCUUUURRRRSSSSIIIIVVVVEEEEOOOONNNN option to _u_s_c_t_l_s_e_m_a(3P). Recursive semaphores
- permit the current owner to acquire the semaphore multiple times. A
- matching number of _u_s_v_s_e_m_a(3P) calls will release the semaphore.
- Recursive semaphores only work with semaphores that have been initialized
- to 1 (i.e. mutual exclusion semaphores).
-
- For polling semaphores, the caller is never actually suspended - either 1
- or 0 is returned based on whether the semaphore was available. If the
- semaphore was not available, the process is placed on the queue of
- processes waiting for the semaphore and the caller must perform either a
- _p_o_l_l(2) or _s_e_l_e_c_t(2) on the file descriptor returned by
- _u_s_o_p_e_n_p_o_l_l_s_e_m_a(3P) to determine when the semaphore becomes available.
- The PPPPOOOOLLLLLLLLIIIINNNN event should be used with _p_o_l_l(2). The semaphore file
- descriptor should be passed in as a read descriptor for _s_e_l_e_c_t(2). The
- caller must not call _u_s_p_s_e_m_a again until having acquired the semaphore by
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- UUUUSSSSPPPPSSSSEEEEMMMMAAAA((((3333PPPP)))) UUUUSSSSPPPPSSSSEEEEMMMMAAAA((((3333PPPP))))
-
-
-
- receiving a ready status from _s_e_l_e_c_t or _p_o_l_l. Use _u_s_c_p_s_e_m_a(3P) to
- acquire a semaphore if its available but not be queued if it isn't.
-
- Note that only in the transition from unavailable to available will the
- file descriptor of a pollable semaphore trip a _p_o_l_l(2) or _s_e_l_e_c_t(2) call.
- In other words, _p_o_l_l(2) or _s_e_l_e_c_t(2) will block if you have already
- successfully acquired the semaphore with _u_s_p_s_e_m_a.
-
- In order to use a semaphore, the caller must have joined the shared arena
- out of which the semaphore is allocated (via _u_s_i_n_i_t(3P)), and have a file
- descriptor to a _u_s_e_m_a device to suspend on. As a convenience, _u_s_p_s_e_m_a
- will automatically do this for members of a share group, or for related
- (via _f_o_r_k(2)) processes. This automatic facility can generate the same
- errors as _u_s_i_n_i_t(3P), and _u_s_o_p_e_n_p_o_l_l_s_e_m_a(3P). These errors will be
- passed back to the caller. If tracing is enabled (see _u_s_i_n_i_t(_3_P)) then
- any errors will cause a message to be printed to _s_t_d_e_r_r. To avoid these
- errors and therefore not need to check for errors on every _u_s_p_s_e_m_a call,
- have each process call _u_s_i_n_i_t(_3_P) and each user of a pollable semaphore
- call _u_s_o_p_e_n_p_o_l_l_s_e_m_a(3P).
-
- The following errors can occur due to misuse of a semaphore:
-
- [EBADF] The underlying file descriptor for the semaphore was
- closed or re-used by the application.
-
- [EBADF] _u_s_p_s_e_m_a was called on a polling semaphore which was not
- available and no one had ever done a _u_s_o_p_e_n_p_o_l_l_s_e_m_a(3P)).
-
- [ERANGE] The semaphore queue overflowed. This is caused when using
- a polling semaphore and the caller has 'double-tripped',
- i.e. calls _u_s_p_s_e_m_a more than once without properly having
- received the semaphore via _p_o_l_l(2) or _s_e_l_e_c_t(2). This can
- also occur if the number of users of a semaphore exceeds
- the number that the arena was originally configured for.
- This will never happen if ALL users register with the
- arena via _u_s_i_n_i_t(3P).
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- uscpsema(3P), usctlsema(3P), usinit(3P), usinitsema(3P), usnewsema(3P),
- usnewpollsema(3P), usopenpollsema(3P), ustestsema(3P), usvsema(3P),
- usema(7M).
-
- DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
- Upon successful completion the semaphore has been acquired and a value of
- 1 is returned. For polling semaphores, 0 is returned if the semaphore is
- unavailable. On error, -1 is returned and _e_r_r_n_o is set to indicate the
- error.
-
- FFFFUUUUTTTTUUUURRRREEEE DDDDIIIIRRRREEEECCCCTTTTIIIIOOOONNNNSSSS
- To facilitate error handling, _u_s_p_s_e_m_a will return distinctive affirmative
- results based on whether the semaphore was acquired normally or was
- acquired due to the owner having abnormally terminated.
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-